#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
map<string,int> t;
inline bool check(string s){
	int p=0,m=0;
	int len=s.length();
	if(s[0]=='.'||s[0]==':'||s[len-1]=='.'||s[len-1]==':') return 0;
	for(int i=0;i<len;++i){
		if(s[i]=='.'){
			if(m>0||s[i-1]=='.'||s[i+1]=='.'||s[i+1]==':') return 0;
			p++;
		}
		if(s[i]==':'){
			if(p<3||s[i-1]=='.'||s[i+1]=='.') return 0;
			m++;
		}
	}
	if(p>3||m>1||p<3||m<1) return 0;
	int num=0;
	for(int i=0;i<len;++i){
		if(s[i]=='.'||s[i]==':'){
			if(num>255) return 0;
			num=0;
		}
		else{
			if(num==0&&s[i-1]==48) return 0;
			num=num*10+(s[i]^48);
		}
		if(num>65535) return 0;
	}
	if(num>65535) return 0;
	return 1;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	t.clear();
	int n;
	char op[10];
	string ad;
	scanf("%d",&n);
	for(int j=1;j<=n;++j){
		scanf("%s",op);
		cin>>ad;
		if(!check(ad)){
			printf("ERR\n");
			continue;
		}
		if(op[0]=='S'){
			if(t[ad]>0) printf("FAIL\n");
			else{
				t[ad]=j;
				printf("OK\n");
			}
		}
		else{
			if(t[ad]==0)
				printf("FAIL\n");
			else
				printf("%d\n",t[ad]);
		}
	}
	return 0;
}
